package com.example.sqlitelogin;

import static com.example.sqlitelogin.WeatherActivity.urlClimb;

import android.content.Intent;
import android.graphics.Color;
import android.graphics.Paint;
import android.os.Bundle;

import androidx.fragment.app.Fragment;
import androidx.viewpager2.widget.ViewPager2;
import com.example.sqlitelogin.WeatherActivity;

import android.os.StrictMode;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.CompoundButton;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.Switch;
import android.widget.TextView;
import android.widget.VideoView;

import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.JSONObject;
import com.example.sqlitelogin.tools.DataChange;

import java.util.ArrayList;
import java.util.Calendar;

/**
 * A simple {@link Fragment} subclass.
 * Use the {@link BlankFragment1#newInstance} factory method to
 * create an instance of this fragment.
 */
public class BlankFragment1 extends Fragment {

    private ViewPager2 viewPager3;
    private static final String ARG_TEXT  = "param1";
    private static final String ARG_TEXT2 = "param2";
    private static final String ARG_TEXT3 = "param3";
    private static final String ARG_TEXT4 = "param4";
    private static final String ARG_TEXT5 = "param5";
    private static final String ARG_TEXT6 = "param6";
    private static final String ARG_TEXT7 = "param7";
    private static final String ARG_TEXT8 = "param8";
    private static final String ARG_TEXT9 = "param9";
    private static final String ARG_TEXT10 = "param10";
    private static final String ARG_TEXT11 = "param11";
    private static final String ARG_TEXT12 = "param12";
    private static final String ARG_TEXT13 = "param13";
    private static final String ARG_TEXT14 = "param14";
    private String name1,name2,name3;
    private ImageView a,b,c,d,current;
    private LinearLayout top1,top2,top3,top4;

    // TODO: Rename and change types of parameters
    private String mTextString;
    private String mTextString2;
    private String mTextString3;
    private String mTextString4;
    private String mTextString5;
    private String mTextString6;
    private String mTextString7;
    private String mTextString8;
    private String mTextString9;
    private String mTextString10;
    private String mTextString11;
    private String mTextString12;
    private String mTextString13;
    private String mTextString14;





    View rootView;

    public BlankFragment1() {
        // Required empty public constructor
    }

    /**
     * Use this factory method to create a new instance of
     * this fragment using the provided parameters.
     *
     * @param param1 Parameter 1.

     * @return A new instance of fragment BlankFragment1.
     */
    // TODO: Rename and change types and number of parameters
    public static BlankFragment1 newInstance(String param1,String param2,String param3,String param4,String param5,String param6,String param7,String param8,String param9,String param10,String param11,String param12,String param13,String param14 ) {
        BlankFragment1 fragment = new BlankFragment1();
        Bundle args = new Bundle();
        args.putString(ARG_TEXT, param1);
        args.putString(ARG_TEXT2, param2);
        args.putString(ARG_TEXT3, param3);
        args.putString(ARG_TEXT4, param4);
        args.putString(ARG_TEXT5, param5);
        args.putString(ARG_TEXT6, param6);
        args.putString(ARG_TEXT7, param7);
        args.putString(ARG_TEXT8, param8);
        args.putString(ARG_TEXT9, param9);
        args.putString(ARG_TEXT10, param10);
        args.putString(ARG_TEXT11, param11);
        args.putString(ARG_TEXT12, param12);
        args.putString(ARG_TEXT13, param13);
        args.putString(ARG_TEXT14, param14);


        fragment.setArguments(args);
        return fragment;
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        if (getArguments() != null) {
            mTextString = getArguments().getString(ARG_TEXT);
            mTextString2 = getArguments().getString(ARG_TEXT2);
            mTextString3 = getArguments().getString(ARG_TEXT3);

            mTextString4 = getArguments().getString(ARG_TEXT4);
            mTextString5 = getArguments().getString(ARG_TEXT5);
            mTextString6 = getArguments().getString(ARG_TEXT6);
            mTextString7 = getArguments().getString(ARG_TEXT7);
            mTextString8 = getArguments().getString(ARG_TEXT8);
            mTextString9 = getArguments().getString(ARG_TEXT9);
            mTextString10 = getArguments().getString(ARG_TEXT10);
            mTextString11 = getArguments().getString(ARG_TEXT11);
            mTextString12 = getArguments().getString(ARG_TEXT12);
            mTextString13 = getArguments().getString(ARG_TEXT13);
            mTextString14 = getArguments().getString(ARG_TEXT14);


        }
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        if(rootView==null){
            rootView= inflater.inflate(R.layout.fragment_blank1, container, false);
        }
        initView();
        return rootView;
    }

    private void initView() {
        TextView textView=rootView.findViewById(R.id.text1);
        TextView date=rootView.findViewById(R.id.iv_text1);

        LinearLayout kongBackGrd=rootView.findViewById(R.id.kong_backgrd);
        TextView kongText1=rootView.findViewById(R.id.kong_text_1);
        TextView kongText2=rootView.findViewById(R.id.kong_text2);

        LinearLayout lightGrd1=rootView.findViewById(R.id.light_backgrd);
        TextView light1_text1=rootView.findViewById(R.id.light_text_1);
        TextView light1_text2=rootView.findViewById(R.id.light_text2);

        LinearLayout wifiGrd=rootView.findViewById(R.id.tab_wifi);
        TextView wifi_text1=rootView.findViewById(R.id.wifi_text1);
        TextView wifi_text2=rootView.findViewById(R.id.wifi_text2);

        LinearLayout tvGrd=rootView.findViewById(R.id.tab_tv);
        TextView tv_text1=rootView.findViewById(R.id.tv_text1);
        TextView tv_text2=rootView.findViewById(R.id.tv_text2);

        LinearLayout bed_kong=rootView.findViewById(R.id.bed_kong);
        TextView bed_kong_text1=rootView.findViewById(R.id.bed_kong_text1);
        TextView bed_kong_text2=rootView.findViewById(R.id.bed_kong_text2);

        LinearLayout bed_light=rootView.findViewById(R.id.bed_light);
        TextView bed_light_text1=rootView.findViewById(R.id.bed_light_text1);
        TextView bed_light_text2=rootView.findViewById(R.id.bed_light_text2);

        LinearLayout kictGrd=rootView.findViewById(R.id.kict_light);
        TextView kict_text1=rootView.findViewById(R.id.kict_light_text1);
        TextView kict_text2=rootView.findViewById(R.id.kict_light_text2);

        Button btn1=rootView.findViewById(R.id.btn1);
        Button btn2=rootView.findViewById(R.id.btn2);
        Button btn3=rootView.findViewById(R.id.btn3);
        Button btn4=rootView.findViewById(R.id.btn4);

        LinearLayout ke1=rootView.findViewById(R.id.ke1);
        LinearLayout ke2=rootView.findViewById(R.id.ke2);
        LinearLayout woShi=rootView.findViewById(R.id.woShi);






        Calendar calendar = Calendar.getInstance();
        //获取系统的日期
//年
        int year = calendar.get(Calendar.YEAR);
//月
        int month = calendar.get(Calendar.MONTH)+1;
//日
        int day = calendar.get(Calendar.DAY_OF_MONTH);
//获取系统时间
//小时
        int hour = calendar.get(Calendar.HOUR_OF_DAY);
//分钟
        int minute = calendar.get(Calendar.MINUTE);
//秒
        int second = calendar.get(Calendar.SECOND);

        if(hour>=5&&hour<12) {
            textView.setText("早上好！");
        }
        if(hour>=12&&hour<18) {
            textView.setText("下午好！");
        }
        if(hour>=18) {
            textView.setText("晚上好！");
        }
        if(hour<5) {
            textView.setText("晚上好！");
        }
        date.setText(year+"年"+month+"月"+day+"日");
        btn1.setTextSize(15);



        LinearLayout weather=rootView.findViewById(R.id.weather);


        TextView locat=rootView.findViewById(R.id.location);

        locat.setText(mTextString);
        TextView temp_0=rootView.findViewById(R.id.temp_te);
        temp_0.setText(mTextString2+"℃");
        TextView daylight_0=rootView.findViewById(R.id.daylight);
        daylight_0.setText("今日 "+mTextString3);


        Switch mSwitch1 = rootView.findViewById(R.id.kong);
        // 添加监听
        mSwitch1.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                if (isChecked){
                    kongText1.setTextColor(rootView.getResources().getColor(R.color.white));
                    kongText2.setTextColor(getResources().getColor(R.color.white));
                    kongBackGrd.setBackground(getResources().getDrawable(R.drawable.round));
                }else {
                    kongText1.setTextColor(rootView.getResources().getColor(R.color.black));
                    kongText2.setTextColor(getResources().getColor(R.color.black));
                    kongBackGrd.setBackground(getResources().getDrawable(R.drawable.backgrd));
                }
            }
        });

        Switch mSwitch2 = rootView.findViewById(R.id.light_switch);
        mSwitch2.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                if (isChecked){
                    light1_text1.setTextColor(rootView.getResources().getColor(R.color.white));
                    light1_text2.setTextColor(getResources().getColor(R.color.white));
                    lightGrd1.setBackground(getResources().getDrawable(R.drawable.round));
                }else {
                    light1_text1.setTextColor(rootView.getResources().getColor(R.color.black));
                    light1_text2.setTextColor(getResources().getColor(R.color.black));
                    lightGrd1.setBackground(getResources().getDrawable(R.drawable.backgrd));
                }
            }
        });

        Switch mSwitch3 = rootView.findViewById(R.id.wifi_switch);
        mSwitch3.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                if (isChecked){
                    wifi_text1.setTextColor(rootView.getResources().getColor(R.color.white));
                    wifi_text2.setTextColor(getResources().getColor(R.color.white));
                    wifiGrd.setBackground(getResources().getDrawable(R.drawable.round));
                }else {
                    wifi_text1.setTextColor(rootView.getResources().getColor(R.color.black));
                    wifi_text2.setTextColor(getResources().getColor(R.color.black));
                    wifiGrd.setBackground(getResources().getDrawable(R.drawable.backgrd));
                }
            }
        });


        Switch mSwitch4 = rootView.findViewById(R.id.tv_switch);
        mSwitch4.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                if (isChecked){
                    tv_text1.setTextColor(rootView.getResources().getColor(R.color.white));
                    tv_text2.setTextColor(getResources().getColor(R.color.white));
                    tvGrd.setBackground(getResources().getDrawable(R.drawable.round));
                }else {
                    tv_text1.setTextColor(rootView.getResources().getColor(R.color.black));
                    tv_text2.setTextColor(getResources().getColor(R.color.black));
                    tvGrd.setBackground(getResources().getDrawable(R.drawable.backgrd));
                }
            }
        });

        Switch mSwitch5 = rootView.findViewById(R.id.bed_kong_switch);
        mSwitch5.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                if (isChecked){
                    bed_kong_text1.setTextColor(rootView.getResources().getColor(R.color.white));
                    bed_kong_text2.setTextColor(getResources().getColor(R.color.white));
                    bed_kong.setBackground(getResources().getDrawable(R.drawable.round));
                }else {
                    bed_kong_text1.setTextColor(rootView.getResources().getColor(R.color.black));
                    bed_kong_text2.setTextColor(getResources().getColor(R.color.black));
                    bed_kong.setBackground(getResources().getDrawable(R.drawable.backgrd));
                }
            }
        });

        Switch mSwitch6 = rootView.findViewById(R.id.bed_light_switch);
        mSwitch6.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                if (isChecked){
                    bed_light_text1.setTextColor(rootView.getResources().getColor(R.color.white));
                    bed_light_text2.setTextColor(getResources().getColor(R.color.white));
                    bed_light.setBackground(getResources().getDrawable(R.drawable.round));
                }else {
                    bed_light_text1.setTextColor(rootView.getResources().getColor(R.color.black));
                    bed_light_text2.setTextColor(getResources().getColor(R.color.black));
                    bed_light.setBackground(getResources().getDrawable(R.drawable.backgrd));
                }
            }
        });


        btn1.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                btn1.setTextSize(15);
                btn2.setTextSize(12);
                btn3.setTextSize(12);
                btn4.setTextSize(12);
                kongBackGrd.setVisibility(kongBackGrd.VISIBLE);
                tvGrd.setVisibility(tvGrd.VISIBLE);
                wifiGrd.setVisibility(wifiGrd.VISIBLE);
                lightGrd1.setVisibility(lightGrd1.VISIBLE);
                bed_kong.setVisibility(bed_kong.VISIBLE);
                bed_light.setVisibility(bed_light.VISIBLE);
                kictGrd.setVisibility(kictGrd.VISIBLE);

            }
        });
        btn2.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                btn1.setTextSize(12);
                btn2.setTextSize(15);
                btn3.setTextSize(12);
                btn4.setTextSize(12);
                kongBackGrd.setVisibility(kongBackGrd.VISIBLE);
                tvGrd.setVisibility(tvGrd.VISIBLE);
                wifiGrd.setVisibility(wifiGrd.VISIBLE);
                lightGrd1.setVisibility(lightGrd1.VISIBLE);
                bed_kong.setVisibility(bed_kong.GONE);
                bed_light.setVisibility(bed_light.GONE);
                kictGrd.setVisibility(kictGrd.GONE);

            }
        });
        btn3.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                btn1.setTextSize(12);
                btn2.setTextSize(12);
                btn3.setTextSize(15);
                btn4.setTextSize(12);
                kongBackGrd.setVisibility(kongBackGrd.GONE);
                tvGrd.setVisibility(tvGrd.GONE);
                wifiGrd.setVisibility(wifiGrd.GONE);
                lightGrd1.setVisibility(lightGrd1.GONE);
                bed_kong.setVisibility(bed_kong.VISIBLE);
                bed_light.setVisibility(bed_light.VISIBLE);
                kictGrd.setVisibility(kictGrd.GONE);

            }
        });
        btn4.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                btn1.setTextSize(12);
                btn2.setTextSize(12);
                btn3.setTextSize(12);
                btn4.setTextSize(15);
                kongBackGrd.setVisibility(kongBackGrd.GONE);
                tvGrd.setVisibility(tvGrd.GONE);
                wifiGrd.setVisibility(wifiGrd.GONE);
                lightGrd1.setVisibility(lightGrd1.GONE);
                bed_kong.setVisibility(bed_kong.GONE);
                bed_light.setVisibility(bed_light.GONE);
                kictGrd.setVisibility(kictGrd.VISIBLE);
            }
        });

        weather.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent1=new Intent(getActivity(),WeatherActivity.class);
                Bundle bundle = new Bundle();
                bundle.putString("city",mTextString);
                bundle.putString("temp",mTextString2);
                bundle.putString("daylight",mTextString3);

                bundle.putString("direct",mTextString4);
                bundle.putString("power",mTextString5);
                bundle.putString("aqi",mTextString6);

//                Log.e("leo",mTextString6);

                bundle.putString("year", String.valueOf(year));
                bundle.putString("month", String.valueOf(month));
                bundle.putString("day", String.valueOf(day));

                bundle.putString("date2", mTextString7);
                bundle.putString("temperature2", mTextString8);
                bundle.putString("weather2", mTextString9);
                bundle.putString("direct2", mTextString10);

                bundle.putString("date3", mTextString11);
                bundle.putString("temperature3", mTextString12);
                bundle.putString("weather3", mTextString13);
                bundle.putString("direct3", mTextString14);

                intent1.putExtras(bundle);
                startActivity(intent1);

            }
        });



        kongBackGrd.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent2=new Intent(getActivity(),KongActivity.class);
                startActivity(intent2);
            }
        });
        bed_kong.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent3=new Intent(getActivity(),Kong2Activity.class);
                startActivity(intent3);
            }
        });
        tvGrd.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent4=new Intent(getActivity(),TVActivity.class);
                startActivity(intent4);
            }
        });
        lightGrd1.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent5=new Intent(getActivity(),LightOneActivity.class);
                startActivity(intent5);
            }
        });
        bed_light.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent6=new Intent(getActivity(),LightTwoActivity.class);
                startActivity(intent6);
            }
        });

        kictGrd.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent7=new Intent(getActivity(),LightThreeActivity.class);
                startActivity(intent7);
            }
        });

        wifiGrd.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent8=new Intent(getActivity(),WiFiActivity.class);
                startActivity(intent8);
            }
        });

    }

    @Override
    public void onResume() {
        super.onResume();
        if (DataChange.Cty!=null){
            name2=DataChange.Te;
            name3=DataChange.dalt;
            name1=DataChange.Cty+"市";
            TextView locat=rootView.findViewById(R.id.location);

            locat.setText(name1);

            TextView temp_0=rootView.findViewById(R.id.temp_te);
            temp_0.setText(name2+"℃");

            TextView daylight_0=rootView.findViewById(R.id.daylight);
            daylight_0.setText("今日 "+name3);
        }

    }
}